//
//  AlertView.swift
//  loveHHEveryDay
//
//  Created by yw on 2025/4/21.
//

import UIKit

class AlertView: UIView {
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var contentLabel: UILabel!
    @IBOutlet weak var confirmBtn: UIButton!
    
    @IBOutlet weak var cancelBtn: UIButton!
    
    var confirmBlock:(_ : () -> Void)?
    var cancelBlock:(_ : ()-> Void)?
    
    override func awakeFromNib() {
        super.awakeFromNib()
        let gradientLayer = CAGradientLayer()
        gradientLayer.frame = self.confirmBtn.bounds
        gradientLayer.colors = [UIColor(named: "color_pink_01")!.cgColor, UIColor(named: "color_pink_02")!.cgColor]
        gradientLayer.startPoint = CGPoint(x: 0, y: 0)
        gradientLayer.endPoint = CGPoint(x: 1, y: 0)
        
        // 将渐变色图层添加到按钮的 layer 中
        self.confirmBtn.layer.insertSublayer(gradientLayer, at: 0)
        self.confirmBtn.layer.cornerRadius = 25
        self.confirmBtn.clipsToBounds = true
        self.confirmBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .bold)
        
        self.cancelBtn.layer.cornerRadius = 25
        self.cancelBtn.clipsToBounds = true
        self.cancelBtn.layer.borderWidth = 2
        self.cancelBtn.layer.borderColor = UIColor(named: "color_pink_01")!.cgColor
        self.layer.cornerRadius = 20
        self.clipsToBounds = true
    }
    
    
    class func createAlertView(
        title:String = "提示",
        content:String,
        height:CGFloat = 330,
        confirmBlock:(_:() -> Void) = {},
        cancelBlock:(_:() ->Void) = {}
    ) -> AlertView {
        let view = Bundle.main.loadNibNamed("AlertView", owner: nil)?.last as! AlertView
        view.frame = CGRectMake(0, 0, kScreenWidth, height)
        view.contentLabel.text = content
        view.confirmBlock = confirmBlock
        view.cancelBlock = cancelBlock
        return view
        
    }
    
    
    @IBAction func cancelBtnClick(_ sender: UIButton) {
        self.hideToView()
        self.cancelBlock?()
    }
    
    @IBAction func confirmBtnClick(_ sender: UIButton) {
        self.hideToView()
        self.confirmBlock?()
    }
    
    
}
